package demo2;

public class Computer {
    public void open(){
        System.out.println("开机------");
    }
    public void close(){
        System.out.println("关机----");
    }
    public void useUsb(USB usb){ //以接口引用接收方便传不同的对象
        usb.openDevice();
        if(usb instanceof Mouse){   //  instanceof关键字是判断usb引用对象是否是mouse
            Mouse mouse =(Mouse) usb;//强转为Mouse型
            mouse.click();
            }else{
            KeyBoard keyBoard =(KeyBoard)usb;
            keyBoard.input();
        }
        usb.closeDevice();
    }
}
